1701A - Grass Field - CodeForces Solution


implementation *800

Please click on ads to support us..

Python Code:

n = int(input())
l=[ ]
for i in range(n ):
    row_1 = input().split()
    row_2 = input().split()
    kolli = [int(i) for i in row_1 + row_2]
    sefr , yek =  0 , 0
    for i in kolli:
        if i == 0: 
            sefr += 1
        else:
            yek += 1
    if sefr == 4 : 
        l.append(0)
    elif yek == 2 or yek == 1 or yek == 3:
        l.append(1)
    else:
        l.append(2)
for i in l :
    print(i)

C++ Code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int x=2,y=2;
        int a[x][y];
        for(int i=0;i<x;i++)
        {
            for(int j=0;j<y;j++)
            {
                cin>>a[i][j];
            }
        }
        int cnt=0;
        for(int i=0;i<x;i++)
        {
            for(int j=0;j<y;j++)
            {
                if(a[0][0]==0&&a[0][1]==0&&a[1][0]==0&&a[1][1]==0)
                   {
                    cnt=0;
                    break;
                   }
                else if(a[0][0]==1&&a[0][1]==1&&a[1][0]==1&&a[1][1]==1)
                   {
                    cnt=2;
                    break;
                   }
                else
                {
                    cnt=1;
                    break;
                }


            }
        }
        if(cnt)
        {
            cout<<cnt<<endl;
        }
        else
            cout<<0<<endl;



    }




    }


Comments

Submit
0 Comments
More Questions

242. Valid Anagram
141. Linked List Cycle
21. Merge Two Sorted Lists
203. Remove Linked List Elements
733. Flood Fill
206. Reverse Linked List
83. Remove Duplicates from Sorted List
116. Populating Next Right Pointers in Each Node
145. Binary Tree Postorder Traversal
94. Binary Tree Inorder Traversal
101. Symmetric Tree
77. Combinations
46. Permutations
226. Invert Binary Tree
112. Path Sum
1556A - A Variety of Operations
136. Single Number
169. Majority Element
119. Pascal's Triangle II
409. Longest Palindrome
1574A - Regular Bracket Sequences
1574B - Combinatorics Homework
1567A - Domino Disaster
1593A - Elections
1607A - Linear Keyboard
EQUALCOIN Equal Coins
XOREQN Xor Equation
MAKEPAL Weird Palindrome Making
HILLSEQ Hill Sequence
MAXBRIDGE Maximise the bridges